package com.huirui.server.controller.admin;

import com.huirui.server.pojo.entity.Carousel;
import com.huirui.server.pojo.result.Result;
import com.huirui.server.pojo.vo.CarouselVo;
import com.huirui.server.service.CarouselService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("adminCarouselController")
@RequestMapping("/admin/carousel")
@Slf4j
@Validated
@Tag(name = "轮播图管理", description = "轮播图管理")
public class CarouselController {
    @Resource
    private CarouselService carouselService;

    @GetMapping("/list")
    @Operation(summary = "获取轮播图列表")
    public Result<List<CarouselVo>> getAllCarousel() {
        List<CarouselVo> list = carouselService.getAllCarousel();
        return Result.success(list);
    }

    @PostMapping("/add")
    @Operation(summary = "添加商品轮播图")
    public Result<Void> addCarousel(@RequestBody CarouselVo carouselVo) {
        carouselService.addCarousel(carouselVo);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除轮播图")
    public Result<Void> deleteCarousel(@PathVariable Long id) {
        carouselService
                .lambdaUpdate()
                .eq(Carousel::getId, id)
                .remove();
        return Result.success();
    }

    @PutMapping
    @Operation(summary = "更新轮播图信息")
    public Result<Void> updateCarousel(@RequestBody CarouselVo carouselVo) {
        carouselService.updateCarousel(carouselVo);
        return Result.success();
    }
}